
<?php
/*
 * Following code will list all the products
 */

// array for JSON response
$response = array();
if(isset($_POST['uid'])){
	$uid = $_POST['uid'];
	// include db connect class
	require_once __DIR__ . '/db_connect.php';
	 
	// connecting to db
	$db = new DB_CONNECT();
	
	
	mysql_query("set names 'utf8'");
	//mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'");
	// get all products from products table 
	$result = mysql_query("SELECT a.id, TEN_DIA_DIEM, TEN_MON_AN, DIA_CHI, THANH_PHO,
 		SO_DIEN_THOAI, MO_TA, LATITUDE, LONGITUDE, LOAI_MON_AN_id, QUAN_HUYEN 
			FROM MON_AN a join USERS b on a.USERS_id = b.id and b.unique_id = '".$uid."' 
			ORDER BY TEN_MON_AN ASC") 
		or die(mysql_error());
	 
	// check for empty result
	if (mysql_num_rows($result) > 0) {
	    // looping through all results
	    // products node
	    $response["foods"] = array();
	 
	    while ($row = mysql_fetch_array($result)) {
	        // temp user array
	        $food = array();
	        $food["id"] = $row["id"];
	        $food["TEN_DIA_DIEM"] = $row["TEN_DIA_DIEM"];
	        $food["TEN_MON_AN"] = $row["TEN_MON_AN"];
	        $food["DIA_CHI"] = $row["DIA_CHI"];
	        $food["THANH_PHO"] = $row["THANH_PHO"];
	        $food["SO_DIEN_THOAI"] = $row["SO_DIEN_THOAI"];
	        $food["MO_TA"] = $row["MO_TA"];
	        $food["LATITUDE"] = $row["LATITUDE"];
	        $food["LONGITUDE"] = $row["LONGITUDE"];
	        $food["LOAI_MON_AN_id"] = $row["LOAI_MON_AN_id"];
	        $food["QUAN_HUYEN"] = $row["QUAN_HUYEN"];
	        // push single product into final response array
	        array_push($response["foods"], $food);
	    }
	    // success
	    $response["success"] = 1;
	    // echoing JSON response
	    echo utf8_encode(json_encode($response));
	} else {
	    // no products found
	    $response["success"] = 0;
	    $response["message"] = "No foods found";
	 
	    // echo no users JSON
	    print utf8_encode(json_encode($response));
	}
} else {
	$response["success"] = 0;
	$response["message"] = "Required field(s) is missing";
	echo json_encode($response);
}
?>


